import myAxios from "@/request";
import { ApiResponse } from "@/types";

interface commentGetRequest {
  id: number;
  blogId: number;
  username: string;
  avatar: string;
  content: string;
  createdAt: string;
}

interface commentCreateRequest {
  blogId: number;
  content: string;
}

/**
 * 创建评论
 * @param params
 * @returns
 */
export const createComment = async (params: commentCreateRequest) => {
  return await myAxios.request({
    url: `/blog/${params.blogId}/comment`,
    method: "post",
    headers: {
      "Content-Type": "application/json",
    },
    data: {
      content: params.content,
    },
  });
};

/**
 * 删除评论
 * @param params
 * @returns
 */
export const deleteComment = async (params: number) => {
  return await myAxios.request({
    url: `/dleComment/${params}`,
    method: "delete",
  });
};

/**
 * 获取评论列表
 * @param params
 * @returns
 */
export const getCommentList = async (params: number) => {
  const response = await myAxios.get<ApiResponse<commentGetRequest[]>>(
    `/blog/${params}/comments`
  );
  return response.data;
};
